package com.uqbar.pacman.scenes;

import java.awt.Color;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import com.uqbar.pacman.components.Ghost;
import com.uqbar.pacman.components.Marcador;
import com.uqbar.pacman.components.Pacman;
import com.uqbar.pacman.components.Position;
import com.uqbar.pacman.components.RegularPacDot;
import com.uqbar.pacman.endScene.EndScene;
import com.uqbar.pacman.imageComponents.ComponentRender;
import com.uqbar.pacman.imageComponents.CreatorDensityMap;
import com.uqbar.pacman.imageComponents.PacmanSkin;
import com.uqbar.vainilla.GameScene;
import com.uqbar.vainilla.appearances.Sprite;
import com.uqbar.vainilla.sound.Sound;
import com.uqbar.vainilla.sound.SoundBuilder;

public class PacmanScene extends GameScene {
	
	private ComponentRender background;
	private Pacman pacman;
	private Ghost ghost;
	private CreatorDensityMap CreatorDensityMap = new CreatorDensityMap();
	private BufferedImage densityMap;
	private ArrayList<RegularPacDot> dots = new ArrayList<RegularPacDot>();
	private PacmanSkin pskin = new PacmanSkin(210,570);
//	private Sound wakaSound = new SoundBuilder().buildSound("/waka.wav");
	private int maxScore;
	private Marcador marcador = new Marcador(0,0,Color.YELLOW);
	private ComponentRender blinkySkin = new ComponentRender("/blinky.png",0,0);
	private ArrayList<Ghost> ghosts = new ArrayList<Ghost>();	
	
	
	
	public ArrayList<Ghost> getGhosts() {
		return ghosts;
	}

	public void setGhosts(ArrayList<Ghost> ghosts) {
		this.ghosts = ghosts;
	}

	public ComponentRender getBlinkySkin() {
		return blinkySkin;
	}

	public void setBlinkySkin(ComponentRender blinkySkin) {
		this.blinkySkin = blinkySkin;
	}

	public int getMaxScore() {
		return maxScore;
	}

	public void setMaxScore(int maxScore) {
		this.maxScore = maxScore;
	}

	public Marcador getMarcador() {
		return marcador;
	}

	public void setMarcador(Marcador marcador) {
		this.marcador = marcador;
	}
//
//	public Sound getWakaSound() {
//		return wakaSound;
//	}
//
//	public void setWakaSound(Sound wakaSound) {
//		this.wakaSound = wakaSound;
//	}

	public PacmanSkin getPskin() {
		return pskin;
	}

	public void setPskin(PacmanSkin pskin) {
		this.pskin = pskin;
	}

	public ArrayList<RegularPacDot> getDots() {
		return dots;
	}

	public void setDots(ArrayList<RegularPacDot> dots) {
		this.dots = dots;
	}

	public Ghost getGhost() {
		return ghost;
	}

	public void setGhost(Ghost ghost) {
		this.ghost = ghost;
		this.addComponent(ghost);
	}

	public BufferedImage getDensityMap() {
		return densityMap;
	}

	public void setDensityMap(BufferedImage densityMap) {
		this.densityMap = densityMap;
	}

	public Pacman getPacman() {
		return pacman;
	}

	public void setPacman(Pacman pacman) {
		this.pacman = pacman;
		this.addComponent(pacman);
	}

	public ComponentRender getBackground() {
		return background;
	}

	public void setBackground(ComponentRender background) {
		this.background = background;
		this.addComponent(background);
	}
	
	public void renderDots(){
		for(RegularPacDot each : this.getDots()){
			this.addComponent(each);
		}
	}
	
	public PacmanScene(){
		this.setBackground(new ComponentRender("/map1.png",0,0));
		this.setPacman(new Pacman());
		this.setGhost(new Ghost(getPacman(),150,150));
		this.getGhosts().add(getGhost());
		this.setDensityMap(CreatorDensityMap.ProcessImage("/map1.png"));
		ArrayList<Position> pos = this.getGhost().getWalkables();
		for(Position each : pos){
			this.getDots().add(new RegularPacDot(each.getX(),each.getY()));
		}
		this.renderDots();
		this.addComponent(this.getPskin());
		this.addComponent(this.getMarcador());
		this.setMaxScore(this.getDots().size() * 10);
		
		this.getBlinkySkin().setImage(Sprite.fromImage("/blinky.png").scale(0.13));
		this.getBlinkySkin().setAppearance(this.getBlinkySkin().getImage());
		this.addComponent(this.getBlinkySkin());

	}
	
	public void fin(){
		this.getGame().setCurrentScene(new EndScene(this.getMarcador(),20,0));
	}

}
